package test.googlecode.genericdao.jpa;

import java.io.Serializable;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import test.googlecode.genericdao.PersistenceHelper;

public class JPAPersistenceHelper implements PersistenceHelper {
	private EntityManager entityManager;

	@PersistenceContext
	public void setEnityManager(EntityManager enityManager) {
		this.entityManager = enityManager;
	}

	@Override
	public <T> T find(Class<T> type, Serializable id) {
		return (T) entityManager.find(type, id);
	}

	@Override
	public void persist(Object entity) {
		entityManager.persist(entity);
	}

	@Override
	public <T> T getProxy(Class<T> type, Serializable id) {
		return entityManager.getReference(type, id);
	}

	@Override
	public void flush() {
		entityManager.flush();
		
	}

	@Override
	public void clear() {
		entityManager.clear();
	}
}
